﻿using System;
using System.Web;
using System.Data;

namespace msBsc.WebUi
{
    public partial class wfDealerRegTwoUp : msBsc.Cls.BPCustom
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (msBsc.AppLogic.DataAlc.CBizShpCommercialTenantInfo oCBizShpCommercialTenantInfo = new AppLogic.DataAlc.CBizShpCommercialTenantInfo())
                {
                    DataSet ds = oCBizShpCommercialTenantInfo.SelectByUserNme(msBsc.SvRef.UserInfo.Operator);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (ds.Tables[0].Rows[0]["COMM_TENANT_SID"].ToString() == "2" || ds.Tables[0].Rows[0]["COMM_TENANT_SID"].ToString() == "3")
                        {
                            Response.Redirect("/c_DealerRegThree.htm");
                        }
                        if (ds.Tables[0].Rows[0]["COMM_TENANT_SID"].ToString() == "0")
                        {
                            Response.Redirect("/c_DealerRegTwo.htm");
                        }
                        else
                        {
                            SetContrlValue("txtCommNme", ds.Tables[0].Rows[0]["COMM_TENANT_NME"].ToString());
                            SetContrlValue("txtRelId", ds.Tables[0].Rows[0]["COMM_TENANT_ID"].ToString());
                            ShowImgFile(ds.Tables[0].Rows[0]["COMM_TENANT_ID"].ToString());


                            if (ds.Tables[0].Rows[0]["COMM_TYPE_CID"].ToString() == "2")
                            {
                                SetContrlValue("spnCommType", "企业");
                                this.ExecJScript("$('#divCmpList').show();");
                            }
                            else
                            {
                                SetContrlValue("spnCommType", "个人");
                            }
                            //if (msBsc.SvRef.UserInfo.OperType == "2")
                            //{
                            //    SetContrlValue("spnUserNme", msBsc.SvRef.UserInfo.Operator+"(您的帐号已升级成为商户，重新登录后生效！)");
                            //}
                            //else
                            //{
                                SetContrlValue("spnUserNme", msBsc.SvRef.UserInfo.Operator);
                            //}
                        }
                    }
                    else
                    {
                        Response.Redirect("/c_DealerRegOne.htm");
                    }
                }
            }


        }

        private void ShowImgFile(string strRelId)
        {
            using (msBsc.AppLogic.DataAlc.CBizSysFile oCBizSysFile = new msBsc.AppLogic.DataAlc.CBizSysFile())
            {
                DataSet ds = oCBizSysFile.SelectByRelTypeRelId("0", "", strRelId);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i]["RELATION_TYPE_CID2"].ToString() == "SFZ_A")
                    {
                        this.ExecJScript("$('#imgsfza').attr('src', '" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(ds.Tables[0].Rows[i]["FILE_V_PATH"].ToString()) + "');");
                    }
                    else if (ds.Tables[0].Rows[i]["RELATION_TYPE_CID2"].ToString() == "SFZ_B")
                    {
                        this.ExecJScript("$('#imgsfzb').attr('src', '" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(ds.Tables[0].Rows[i]["FILE_V_PATH"].ToString()) + "');");
                    }
                    else if (ds.Tables[0].Rows[i]["RELATION_TYPE_CID2"].ToString() == "CMP_A")
                    {
                        this.ExecJScript("$('#imgcmpa').attr('src', '" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(ds.Tables[0].Rows[i]["FILE_V_PATH"].ToString()) + "');");
                    }
                    else if (ds.Tables[0].Rows[i]["RELATION_TYPE_CID2"].ToString() == "CMP_B")
                    {
                        this.ExecJScript("$('#imgcmpb').attr('src', '" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(ds.Tables[0].Rows[i]["FILE_V_PATH"].ToString()) + "');");
                    }
                }
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "REGIST_STEP1")
            {
                
                    System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
                    transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                    transactionOption.Timeout = new TimeSpan(0, 10, 0);
                    using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
                    {

                        using (msBsc.AppLogic.DataAlc.CBizShpCommercialTenantInfo oCBizShpCommercialTenantInfo = new AppLogic.DataAlc.CBizShpCommercialTenantInfo())
                        {
                            DataSet ds = oCBizShpCommercialTenantInfo.SelectById(this.GetParamHtValue("REL_ID"));
                            if (ds.Tables[0].Rows[0]["COMM_TENANT_SID"].ToString() == "1")
                            {
                                ds.Tables[0].Rows[0]["COMM_TENANT_SID"] = "0";
                                oCBizShpCommercialTenantInfo.Update(ds); 
                                 
                            }
                            else
                            {
                                throw new Exception ("非法调用！");
                            }
                        } 
                        ts.Complete();
                    }

                    this.ExecJScript("window.location.reload(true);");


                //if (this.GetParamHtValue("EMAIL") != string.Empty && this.GetParamHtValue("VALIDATE_CDE") != string.Empty)
                //{
                //    if (this.GetParamHtValue("VALIDATE_CDE") != (string)GetSession(this.sCurrPageRadom + msBsc.Cls.ValidateCode.VALIDATECODEKEY, "2"))
                //    {
                //        this.ExecJScript("jQuery.getValidateImg('J_CheckCodeContainer');");
                //        this.Alert("验证码错误或已过期，请重新录入！");
                //        return;
                //    }
                //    string strcontent = "";
                //    using (System.IO.StreamReader sr = new System.IO.StreamReader(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath) + "Template\\registmailtmp.htm"))
                //    {
                //        strcontent = sr.ReadToEnd();
                //    }
                //    msBsc.AppLogic.Cfg.DesCry ooo=new AppLogic.Cfg.DesCry();
                //    string strurl = msBsc.AppLogic.Cfg.DesCry.encMe(this.GetParamHtValue("EMAIL") + "," + DateTime.Now.ToString(), "rmdes");
                //    strurl = msBsc.AppLogic.Cfg.SystemFileDir.FileDir.httpUrl + "c_RegUserInfoFill.htm?KEY=" + strurl;

                //    strcontent = strcontent.Replace("{REGISTER_MAIL_USER_NME}", this.GetParamHtValue("EMAIL").Split('@')[0]).Replace("{REGISTER_MAIL_URL}", strurl);
                //    msBsc.SvRef.SendEMail oSendEMail = new SvRef.SendEMail();
                //    oSendEMail.SendEmailTo(this.GetParamHtValue("EMAIL").Split('@')[0], this.GetParamHtValue("EMAIL"), "", strcontent);
                //    //this.ExecJScript("debugger;");
                //    this.ExecJScript("LS.set('CURR_REG_MAIL','" + this.GetParamHtValue("EMAIL") + "');");
                //    this.ExecJScript("LS.set('" + this.GetParamHtValue("EMAIL") + "','STEP1');");
                //    this.ExecJScript("LS.set('" + this.GetParamHtValue("EMAIL") + "_RDT','"+DateTime.Now.ToString()+"');");
                //    this.ExecJScript("window.location.href = '/c_RegMailSend.htm';");

                //    SetSession(this.sCurrPageRadom + ValidateCode.VALIDATECODEKEY,null, "2");
                //}
            } 
        }

    }
}